package com.example.test.model;

import java.util.HashMap;
import java.util.List;

import org.json.JSONException;

import android.os.Handler;
import android.util.Log;
import android.widget.Toast;

import com.renn.rennsdk.RennExecutor.CallBack;
import com.renn.rennsdk.RennResponse;
import com.renn.rennsdk.exception.RennException;
import com.renn.rennsdk.param.CommentType;
import com.renn.rennsdk.param.GetStatusParam;
import com.renn.rennsdk.param.ListCommentParam;
import com.renn.rennsdk.param.ListFeedParam;
import com.renn.rennsdk.param.PutCommentParam;
import com.renn.rennsdk.param.PutFeedParam;
import com.renn.rennsdk.param.PutShareUgcParam;
import com.renn.rennsdk.param.PutStatusParam;
import com.renn.rennsdk.param.ShareStatusParam;
import com.renn.rennsdk.param.UGCType;
import com.tencent.weibo.sdk.android.model.GlobalVar;

public class RennAPI {

	public static void sendWeibo(String content)
	{
		if(!GlobalVar.enWhich.equals("all"))
			return ;
		PutStatusParam param=new PutStatusParam();
		param.setContent(content);
		try {
			GlobalVar.rennClient.getRennService().sendAsynRequest(param, null);
		} catch (RennException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public static void getFriline(final Handler handler)
	{
		if(!GlobalVar.enWhich.equals("all"))
			return ;
		ListFeedParam param =new ListFeedParam();
		param.setFeedType("ALL");
		param.setPageNumber(1);
		param.setPageSize(5);
		try {
			GlobalVar.rennClient.getRennService().sendAsynRequest(param, new CallBack() {
				@Override
				public void onSuccess(RennResponse response){
					List<HashMap<String, String>> arrList = RennJsonAnalyzer.timeLineJsonToHasArr(response);
					QQAPI.sendMsg(handler, Constants.MSG_GETTIMELINE_SUCCESS,arrList );
				}
				@Override
				public void onFailed(String errorCode, String errorMessage) {
					Log.v("renn", errorMessage);
				}

			});
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static void comment(final Handler handler,String content,long id)
	{
		if(!GlobalVar.enWhich.equals("all"))
			return ;
		PutCommentParam param =new PutCommentParam();
		param.setContent(content);
		param.setTargetUserId(0l);
		param.setCommentType(CommentType.STATUS);
		param.setEntryOwnerId(GlobalVar.rennClient.getUid());
		param.setEntryId(id);
		try {
			GlobalVar.rennClient.getRennService().sendAsynRequest(param, new CallBack() {
				@Override
				public void onSuccess(RennResponse response){
					List<HashMap<String, String>> arrList = RennJsonAnalyzer.timeLineJsonToHasArr(response);
					QQAPI.sendMsg(handler, Constants.MSG_COMMENT_SUCCESS ,arrList );
				}
				@Override
				public void onFailed(String errorCode, String errorMessage) {
					Log.v("renn", errorMessage);
				}

			});
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static void share(final Handler handler,String content,long id)
	{
		if(!GlobalVar.enWhich.equals("all"))
			return ;
		ShareStatusParam param=new ShareStatusParam();
		param.setContent(content);
		param.setStatusId(id);
		param.setOwnerId(GlobalVar.rennClient.getUid());
		try {
			GlobalVar.rennClient.getRennService().sendAsynRequest(param, new CallBack() {
				@Override
				public void onSuccess(RennResponse response){
					List<HashMap<String, String>> arrList = RennJsonAnalyzer.timeLineJsonToHasArr(response);
					QQAPI.sendMsg(handler, Constants.MSG_REPOST_SUCCESS ,arrList );
				}
				@Override
				public void onFailed(String errorCode, String errorMessage) {
					Log.v("renn", errorMessage);
				}

			});
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static void getCommentList(final Handler handler,String id)
	{
		if(!GlobalVar.enWhich.equals("all"))
			return ;
	 ListCommentParam param =new ListCommentParam();
	 param.setEntryId(Long.parseLong(id));
	 param.setCommentType(CommentType.STATUS);
	 param.setEntryOwnerId(GlobalVar.rennClient.getUid());
	 param.setPageNumber(1);
	 param.setPageSize(50);
	 try {
			GlobalVar.rennClient.getRennService().sendAsynRequest(param, new CallBack() {
				@Override
				public void onSuccess(RennResponse response){
					Log.v("tag", response.toString());
					//List<HashMap<String, String>> arrList = RennJsonAnalyzer.timeLineJsonToHasArr(response);
					//QQAPI.sendMsg(handler, Constants.MSG_REPOST_SUCCESS ,arrList );
				}
				@Override
				public void onFailed(String errorCode, String errorMessage) {
					Log.v("renn", errorMessage);
				}

			});
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	
}
